# Read in the CA county data (TIGER shapefile):
ca_counties <- read_sf(here("data", "ca_counties"), layer = "CA_Counties_TIGER2016") %>% 
  clean_names() %>% 
  dplyr::select(name)

# Read in the oil spill data (ds394 shapefile): 
oil_spill <- read_sf(here("data", "ds394"), layer = "ds394") %>% 
  clean_names() 
# Check the projections
st_crs(ca_counties) # WGS84
st_crs(oil_spill) # NAD83

# Transform CA counties to match oil spill data CRS 
ca_counties <- st_transform(ca_counties, st_crs(oil_spill))

st_crs(ca_counties) # NAD83
# Create a graph to explore the data 
ggplot() + 
  geom_sf(data = ca_counties) +
  geom_sf(data = oil_spill)
# Exploratory interactive map showing the location of oil spill events 
tmap_mode("view")

tm_shape(ca_counties) +
  tm_polygons() +
tm_shape(oil_spill) +
  tm_dots()
# Static chloropleth map in which the fill color for each county depends on the count of inland oil spill events by county for the 2008 oil spill data 

ca_oil_spills <- ca_counties %>% 
  st_join(oil_spill) %>% 
  filter(inlandmari == "Inland")

oil_spill_counts <- ca_oil_spills %>% 
  count(name)

ggplot(data = oil_spill_counts) +
  geom_sf(aes(fill = n), color = "white", size = 0.1) +
    scale_fill_gradientn(colors = c("cadetblue4","orange","violetred")) +
  theme_minimal() +
  labs(fill = "Number of oil spill events",
       x = "\nLongitude",
       y = "Latitude\n")
**Figure 1.** California map of the number of inland oil spill events by country in 2008. Modoc County is not included as it had zero spill events. Data: California Department of Fish and Wildlife. 2009.

Figure 1. California map of the number of inland oil spill events by country in 2008. Modoc County is not included as it had zero spill events. Data: California Department of Fish and Wildlife. 2009.

Citations

California Department of Fish and Wildlife, Office of Spill Prevention and Response. 2009. Oil Spill Incident Tracking [ds394]. https://gis.data.ca.gov/datasets/CDFW::oil-spill-incident-tracking-ds394?geometry=-147.064%2C30.769%2C-91.780%2C43.020